package com.dongdongshop.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.Enum.ResultEnum;
import com.dongdongshop.core.SpecificPrint;
import com.dongdongshop.pojo.TbContent;
import com.dongdongshop.service.TbContentServiceI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("contentController")
public class ContentController {

    Logger logger = LoggerFactory.getLogger(ContentController.class);

    @Reference
    private TbContentServiceI tbContentServiceI;

    @RequestMapping("getContentInfo")
    @ResponseBody
    public SpecificPrint getContentInfo(Long categoryId){
        try {
            List<TbContent> contents = tbContentServiceI.getContentInfo(categoryId);
            logger.info(ResultEnum.SUCCESS.getMessage()+"，参数为：{}",contents);
            return SpecificPrint.response(ResultEnum.SUCCESS).setData(contents);
        }catch (Exception e){
            logger.error(ResultEnum.ERROR.getMessage(),e);
            return SpecificPrint.response(ResultEnum.ERROR);
        }
    }
}
